﻿// <copyright file="SessionExpired.ascx.cs" company="AGR">
// 
// </copyright>

namespace Tfg.Hrs.UI.Controls
{
    using System;
    using System.Web.UI;

    /// <summary>
    /// Inherit the ICallbackEventHandler interface to realize async request.
    /// </summary>
    public partial class SessionExpired : System.Web.UI.UserControl, ICallbackEventHandler
    {
        #region The Callbackhandler

        /// <summary>
        /// You do not need to get any value from the server side.
        /// </summary>
        /// <returns>String Value</returns>
        public string GetCallbackResult()
        {
            return string.Empty;
        }

        /// <summary>
        /// Do not add any code for you just need to interactive with the server.
        /// </summary>
        /// <param name="eventArgument">The Argument</param>
        public void RaiseCallbackEvent(string eventArgument)
        {
        }
        #endregion

        #region Page_Load
        /// <summary>
        /// Handles the Load event of the Page control.
        /// Register the javascript codes to the client, which is benefit to the client to request
        /// the server for async.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["SessionForTest"] = "SessionForTest";
            }

            // Set the client method "client_ReceiveServerData" to receive the value
            // from the server.
            string reference = Page.ClientScript.GetCallbackEventReference(this, string.Empty, "clientReceiveServerData", string.Empty);
            
            // Register a client method "CallServer" to request the server for async.
            string callbackScript = "function clientCallServer()" +
                "{" + reference + ";}";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientCallServer", callbackScript, true);

            // Set the Session's timeout value to the client side. It will be assign to a HiddenField that 
            // it will not affect user use.
            TimeOutHiddenField.Value = Session.Timeout.ToString();
        }
        #endregion
    }
}